package com.weakteam.androidclient.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ProgressBar;
import com.weakteam.androidclient.data.ResourceData;
import com.weakteam.androidclient.data.ResourceDataEventHandler;
import com.weakteam.androidclient.util.MainProperties;

public class LoadResource extends Activity {

    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.load_resource);
        this.progressBar = (ProgressBar) findViewById(R.id.progressBar);
    }

    @Override
    protected void onResume() {
        super.onResume();
        ResourceData resourceData = ResourceData.getInstance();
        resourceData.addResourceDataEventHandler(new ResourceDataEventHandler() {
            @Override
            public void onLoaded() {
                Log.i(MainProperties.LOG_TAG, "Load completed");
                Intent intent = new Intent(getApplicationContext(), MainPage.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);
            }

            @Override
            public void onLoadProgress(float percent) {
                LoadResource.this.progressBar.setProgress((int)(percent * 100.0f));
            }
        });
        resourceData.load(this);
    }

}
